package cc.autoapi.pucong.auto.flow.provider.api.controller;

import cc.autoapi.pucong.auto.flow.core.root.exception.AutoFlowBaseController;
import cc.autoapi.pucong.auto.flow.core.root.exception.AutoFlowExceptionHandler;
import cc.autoapi.pucong.auto.flow.core.root.utils.Res;
import cc.autoapi.pucong.auto.flow.provider.api.entity.dto.ApiNodeTextAiDto;
import cc.autoapi.pucong.auto.flow.provider.api.manager.ApiNodeManager;
import cc.autoapi.pucong.auto.flow.provider.api.entity.dto.ApiNodePreDto;
import cc.autoapi.pucong.auto.flow.provider.api.entity.dto.ApiNodeScriptAiDto;
import cc.autoapi.pucong.auto.flow.provider.api.entity.qo.ApiNodeQo;
import cc.autoapi.pucong.auto.flow.provider.api.entity.vo.ApiNodePreTreeVo;
import cc.autoapi.pucong.auto.flow.provider.api.entity.vo.ApiNodeTreeVo;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author pucong
 * @description api 关联节点信息 controller
 * @create 2024-09-24
 */
@RestController
@Validated
@RequestMapping("/api/apiNode")
public class ApiNodeController extends AutoFlowBaseController implements AutoFlowExceptionHandler{

    @Resource
    private ApiNodeManager apiNodeManager;

    /**
     * 查询设计页面，左侧的工具节点列表
     *
     * @param dto
     * @return
     */
    @GetMapping("/getList")
    public Res<List<ApiNodeTreeVo>> getList(ApiNodeQo dto) {
        List<ApiNodeTreeVo> apiNodeList = apiNodeManager.getList(dto);
        return Res.ok(apiNodeList);
    }

    /**
     * 获取前置节点输出参数
     *
     * @param dto
     * @return
     */
    @PostMapping("/getPreData")
    public Res<List<ApiNodePreTreeVo>> getPreData(@Validated @RequestBody ApiNodePreDto dto) {
        List<ApiNodePreTreeVo> apiNodeList = apiNodeManager.getPreData(dto);
        return Res.ok(apiNodeList);
    }

    /**
     * 根据ai生成脚本内容
     *
     * @param dto
     * @return
     */
    @PostMapping("/getScriptByAi")
    public Res<String> getScriptByAi(@Validated @RequestBody ApiNodeScriptAiDto dto) {
        String script = apiNodeManager.getScriptByAi(dto);
        return Res.ok(script);
    }

    /**
     * 根据ai生成文本内容
     *
     * @param dto
     * @return
     */
    @PostMapping("/getTextByAi")
    public Res<String> getTextByAi(@Validated @RequestBody ApiNodeTextAiDto dto) {
        String text = apiNodeManager.getTextByAi(dto);
        return Res.ok(text);
    }
}
